package com.haohao.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.haohao.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haohao.common.annotation.Log;
import com.haohao.common.core.controller.BaseController;
import com.haohao.common.core.domain.AjaxResult;
import com.haohao.common.enums.BusinessType;
import com.haohao.system.domain.SysAppliances;
import com.haohao.system.service.ISysAppliancesService;
import com.haohao.common.utils.poi.ExcelUtil;
import com.haohao.common.core.page.TableDataInfo;

/**
 * 家电管理Controller
 *
 * @author haohao
 * @date 2024-04-10
 */
@RestController
@RequestMapping("/system/appliances")
public class SysAppliancesController extends BaseController
{
    @Autowired
    private ISysAppliancesService sysAppliancesService;

    /**
     * 查询家电管理列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('system:appliances:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAppliances sysAppliances)
    {
        startPage();
        List<SysAppliances> list = sysAppliancesService.selectSysAppliancesList(sysAppliances);
        return getDataTable(list);
    }



    /**
     * 获取家电管理详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('system:appliances:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysAppliancesService.selectSysAppliancesById(id));
    }

    /**
     * 新增家电管理
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('system:appliances:add')")
    @Log(title = "家电管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAppliances sysAppliances)
    {        sysAppliances.setCount(Long.parseLong("0"));

        return toAjax(sysAppliancesService.insertSysAppliances(sysAppliances));
    }

    /**
     * 修改家电管理
     */

    @Anonymous
    @PreAuthorize("@ss.hasPermi('system:appliances:edit')")
    @Log(title = "家电管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAppliances sysAppliances)
    {
        return toAjax(sysAppliancesService.updateSysAppliances(sysAppliances));
    }

    /**
     * 删除家电管理
     */
    @PreAuthorize("@ss.hasPermi('system:appliances:remove')")
    @Log(title = "家电管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysAppliancesService.deleteSysAppliancesByIds(ids));
    }
}
